home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / TIMECHCK.C < prev    next >
C/C++ Source or Header  |  1993-05-13  |  5KB  |  156 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 05-07-93 (18:03)             Number: 98
  4. From: LOUIS LAUZON                 Refer#: 247
  5.   To: ALL                           Recvd: NO  
  6. Subj: Elapsed Time                   Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. I wrote this utility and although it solves an immediate need, it needs help bad
  9. ly. :-)   It is intended to determine the elapsed time from user keyed start and
  10.  end times.  It also has the ability to carry over the last end time as the next
  11.  start time (+1 second).
  12.  
  13. I don't have nearly the amount of experience with C as I'd like and I know it is
  14.  _very_ sloppy, but could someone explain how to determine the elapsed time if t
  15. he end time is after midnight (24:00).  I made it to that point and am stuck.
  16.  
  17. Also, if anyone could describe a better way of determining the elapsed time rath
  18. er than my endless if() statements, I would be grateful! :-)
  19.  
  20. /*
  21. **      TimeChck.C
  22. **      Louis Lauzon
  23. **      May 6, 1993
  24. **
  25. **      Mix Power C v 2.2.0
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <bios.h>       /* clrscrn() */
  30. #include <conio.h>      /* getche()  */
  31. #include <string.h>     /* strcmp()  */
  32.  
  33. main()
  34. {
  35.     int start_hrs, start_min, start_sec,
  36.         end_hrs, end_min, end_sec,
  37.         total_hrs, total_min, total_sec,
  38.         hold_hrs, hold_min, hold_sec;
  39.     int again = 99;
  40.     char new[80];
  41.  
  42.     while(again)
  43.     {
  44.          clrscrn();
  45.          if(again == 99)        /* First time through program */
  46.          {
  47.               printf("Starting time: (hh:mm:ss) ");
  48.               scanf("%2d%*c%2d%*c%2d", &start_hrs, &start_min, &start_sec);
  49.          }
  50.  
  51.         /***************************************/
  52.         /* Use last end time or new start time */
  53.         /***************************************/
  54.  
  55.          else
  56.          {
  57.               printf("Press ENTER for starting time = %2d:%02d:%02d\n",
  58.                    hold_hrs, hold_min, hold_sec+1);
  59.               printf("or y for new start time.");
  60.               new[0] = getche();
  61.               if(strcmp(new[0],"y") == 0 || strcmp(new[0],"Y") == 0)
  62.               {
  63.                    printf("\nStarting time: (hh:mm:ss) ");
  64.                    scanf("%2d%*c%2d%*c%2d", &start_hrs, &start_min,
  65.                         &start_sec);
  66.               }
  67.  
  68.               /**************************************/
  69.               /* Move last end time into start time */
  70.               /**************************************/
  71.               else
  72.               {
  73.                    start_hrs = hold_hrs;
  74.                    start_min = hold_min;
  75.                    start_sec = hold_sec+=1;
  76.               }
  77.          }
  78.          printf("Ending time: (hh:mm:ss) ");
  79.          scanf("%2d%*c%2d%*c%2d", &end_hrs, &end_min, &end_sec);
  80.          hold_hrs = end_hrs;
  81.          hold_min = end_min;
  82.          hold_sec = end_sec;
  83.  
  84.         /*****************************/
  85.         /* Determine elapsed seconds */
  86.         /*****************************/
  87.  
  88.          if(start_sec < end_sec)
  89.               total_sec = end_sec - start_sec;
  90.          else if(start_sec == end_sec)
  91.               total_sec = 0;
  92.          else if((start_sec > end_sec) && (start_min < end_min))
  93.          {
  94.               if(end_sec == 0)
  95.               {
  96.                    total_sec = (60 - start_sec);
  97.               }
  98.               else
  99.               {
  100.                    total_sec = ((60 - start_sec) + end_sec);
  101.               }
  102.               end_min-=1;
  103.               if(start_hrs < end_hrs)
  104.               {
  105.                    end_hrs-=1;
  106.               }
  107.          }
  108.          else
  109.          {
  110.               total_sec = ((60 - start_sec) + end_sec);
  111.          }
  112.  
  113.         /*****************************/
  114.         /* Determine elapsed minutes */
  115.         /*****************************/
  116.  
  117.          if(start_min < end_min)
  118.               total_min = end_min - start_min;
  119.          else if(start_min == end_min)
  120.               total_min = 0;
  121.          else if((start_min > end_min) && (start_hrs < end_hrs))
  122.          {
  123.               if(end_min == 0)
  124.               {
  125.                    total_min = (60 - start_min);
  126.               }
  127.               else
  128.               {
  129.                    total_min = ((60 - start_min) + end_min);
  130.               }
  131.               end_hrs-=1;
  132.          }
  133.  
  134.         /***************************/
  135.         /* Determine elapsed hours */
  136.         /***************************/
  137.  
  138.          if(start_hrs < end_hrs)
  139.               total_hrs = end_hrs - start_hrs;
  140.          else if(start_hrs == end_hrs)
  141.               total_hrs = 0;
  142.          else
  143.               total_hrs = 99;        /* need to fix code here */
  144.  
  145.          printf("Total Time: %2d:%2d:%2d\n", total_hrs, total_min, total_sec);
  146.          puts("Again ? (0 to quit, any integer and ENTER to continue)");
  147.          scanf("%d", &again);
  148.     }
  149. }
  150.  
  151. --- Maximus/2 2.01wb
  152.  * Origin: The Ozone Layer, Williston, VT. Hst 14.4 / V.32bis (1:325/118)
  153. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  154. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
  155. SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  156.